# -*- coding: utf-8 -*-
# @Time    : 2022/7/16 16:47
# @Author  : catherine
# @Email   : catherine_csq@163.com
# @File    : add_contacts_page.py
# @Software: PyCharm
from time import sleep

from selenium.webdriver.common.by import By

from pages.base_page import BasePage


class AddContactsPage(BasePage):
    '''新建联系人界面类'''
    url='http://192.168.189.1:8081/crm/index.php?m=contacts&a=index'
    #定位器
    name_locator = (By.ID, 'name')
    saltname_locator = (By.ID, 'saltname')
    customer_name_locator = (By.ID, 'customer_name')
    selected_cname_locator = (By.XPATH, '//*[@id="datas"]/tr[1]/td[1]/input[1]')
    confirm_cname_locator = (By.XPATH, '/html/body/div[7]/div[3]/div/button[1]/span')
    position_locator = (By.NAME, 'post')
    mobile_locator = (By.NAME, 'telephone')
    email_locator = (By.NAME, 'email')
    qq_no_locator = (By.NAME, 'qq_no')
    zip_code_locator = (By.NAME, 'zip_code')
    description_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tbody/tr[7]/td[2]/textarea')
    save_add_contacts_locator = (By.XPATH, '/html/body/div[5]/div[2]/div/form/table/tfoot/tr/td[2]/input[1]')

    def input_name(self,name):
        '''输入姓名'''
        self.find_element(self.name_locator).send_keys(name)

    def input_saltname(self,saltname):
        '''输入尊称'''
        self.find_element(self.saltname_locator).send_keys(saltname)

    def input_customer_name(self):
        '''输入所属客户'''
        self.find_element(self.customer_name_locator).click()
        sleep(2)
        self.find_element(self.selected_cname_locator).click()
        self.find_element(self.confirm_cname_locator).click()

    def input_position(self,position):
        '''输入职位'''
        self.find_element(self.position_locator).send_keys(position)

    def input_mobile(self,mobile):
        '''输入电话'''
        self.find_element(self.mobile_locator).send_keys(mobile)

    def input_email(self,email):
        '''输入邮件'''
        self.find_element(self.email_locator).send_keys(email)

    def input_qq_no(self,qq_no):
        '''输入QQ'''
        self.find_element(self.qq_no_locator).send_keys(qq_no)

    def input_zip_code(self,zip_code):
        '''输入邮编'''
        self.find_element(self.zip_code_locator).send_keys(zip_code)

    def input_description(self,description):
        '''输入备注'''
        self.find_element(self.description_locator).send_keys(description)

    def click_save_add_contacts(self):
        '''保存新建联系人'''
        self.find_element(self.save_add_contacts_locator).click()